Welcome to
Introduction to Flask. After watching this video, you will be able to define the Flask web framework and
describe its main features. Explain how to install
Flask on your machines. Describe main
dependencies of Flask, and explain the main
differences between Flask and another Python web
framework called Django. Flask is a micro framework that can create
web applications. It is not opinionated like some other larger
frameworks and does not bind the user to a
specific set of tools. One of the complex dependencies
of Flask is Python. You will run Flask 2.2.2, which requires a minimum
Python version of 3.7. In 2004, Armin Ronacher created the framework as
an April fool's joke. It quickly gained popularity for its ease of use
and extensibility. Flask provides
minimal dependencies you might need to create
a web application. However, it is extensible and many community extensions add additional features to Flask. The main features of Flask
include the following. Flask has a web server that runs applications in
development mode. Flask also comes with a debugger to help
debug applications. The debugger shows
interactive traceback and stack trace in the browser. Flask uses standard Python
logging for application logs, and you can use
the same logger to log custom messages
about your application. Flask provides a way to test different parts
of your application. The testing feature enables developers to follow a
test-driven approach. You can use frameworks
like Pi test and coverage to ensure your
code works as desired. Finally, developers can access
the request and response objects to pull arguments
and customize responses. Now, additional features of
Flask are the following. The framework supports static
assets like CSS files, JavaScript files, and images. Flask provides tags to load static files
in the templates. You can also develop
dynamic pages using Jinja templating
framework and these dynamic pages can display information
that may change for each request or may check
if the user is logged in. Flask provides
routing and supports dynamic URLs that are extremely useful for
RESTful services. You can create routes for different HTTP methods and provide redirection
in your application. You can write global
error handlers in Flask that work on the
application level. Finally, it supports
user session management. Some of the popular community
extensions that can be added to your application
are the following. Flask-SQLAlchemy add support for ORM called SQLAlchemy to Flask, giving developers a way to work with database objects in Python. Flask-Mail provides
the ability to set up an SMTP mail server. Flask-Admin lets you add admin interfaces to Flask
applications easily. Flask-Uploads allow you to add customized file uploading
to your application. Here are some other extensions. Flask-CORS allows
your application to handle Cross-Origin
Resource Sharing, making cross-origin
JavaScript requests possible. Flask-Migrate adds database
migrations to SQLAlchemy ORM. Flask-User adds user
authentication, authorization, and other
user management activities. Marshmallow adds extensive
object serialization and deserialization
support to your code. Finally, celery is a
powerful task queue that can be used for simple background tasks and complex multi-storage
programs and schedules. Flask is available on the Python package
manager called pip, and pip is available in
the lab environment. However, if installing
on your machines, it is recommended that you first create a
virtual environment using the venv or
bin venv module. You can install
Flask version 2.2.2. Now, it is recommended to pin the version number of the dependencies in
your application. This ensures that
the application can be reproduced from scratch in different environments like development, staging,
and production. It also ensures new issues and
bugs are not introduced by mistake when
packages are updated automatically without
a version number. Flask comes with some
built-in dependencies that enable the
various features. Werkzeug implements WSGI or the web server
gateway interface. This is the standard
Python interface between applications
and servers. Jinja is a template
language that renders the pages in
your application. MarkupSafe comes with Jinja. It escapes untrusted input when rendering templates to
avoid injection attacks. ItsDangerous is used to
assign data securely. This helps determine if
data has been tampered with and is used to protect
Flask session cookie. Finally, Click is a framework for writing command-line
applications. It provides the
Flask command and allows adding custom
management commands. To see the built-in
dependencies, you can use the
pip freeze command in the virtual environment, and you can see that all the in-built packages
are installed by default. Now, another Python developer
framework is Django. Here are some key differences
between Flask and Django. Flask games to be a
very light framework. Django, on the other hand, is a full-stack framework. As a result, Flask only provides the basic dependencies needed to create a web application. However, the
developer can choose other extensions that
provide additional features. Django, on the other hand, includes everything you need to create a full-stack application. Also, Flask is very flexible. You can add and remove pieces
in a plug-and-play manner. On the other hand, Django
is opinionated and makes most decisions for
the developer so they can focus on the
application's logic. In this video, you
learned that Flask is a micro framework that ships
with minimal dependencies. To build websites, Flask has features like
debugging servers, routing, templates,
and error handling. Flask can be extended by
using community extensions. Flask can be installed
as a Python package. Django is a full-stack
framework compared to Flask